package com.dupf.upms.server.controller.translate;

import com.dupf.common.base.BaseController;
import com.dupf.upms.common.constant.UpmsResult;
import com.dupf.upms.common.constant.UpmsResultConstant;
import com.dupf.upms.rpc.api.UpmsApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 上传controller
 * Created by dupf on 2018/3/1.
 */
@Controller
@Api(value = "翻译接口", description = "翻译管理")
@RequestMapping("/translate")
public class TranslateController extends BaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(TranslateController.class);

    @ApiOperation(value = "google翻译 本地")
    @RequestMapping(value = "/google-local", method = RequestMethod.POST)
    @ResponseBody
    public Object googleLocal(HttpServletRequest request) throws Exception {

        String requestStr = super.getInputStream(request);
        JSONObject data = JSONObject.fromObject(requestStr);

        String from = data.getString("from");
        String[] tos = data.getString("to").split(",");
        String text = data.getString("text");

        String result = data.optString("result");

        return new UpmsResult(UpmsResultConstant.SUCCESS, result);
    }
}
